using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sudoku.GamePlay;
using System.IO.IsolatedStorage;
using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using System.IO;
using System.Diagnostics;

namespace Sudoku.Utilities
{
	public interface ISaveService
	{
		void SaveGame();
		BoardSaveState LoadGame();
		Boolean IsSaveAvailable();
		void ClearSaveData();
	}

	public class SaveService : ISaveService
	{
		private Game Game;
		private String FileName = "SaveData.xml";
		FileIOService FileService;
			
		public SaveService(Game game)
		{
			Game = game;
			FileService = (FileIOService)Game.Services.GetService(typeof(FileIOService));
		}

		public void SaveGame()
		{
			IBoard boardService = (IBoard)Game.Services.GetService(typeof(IBoard));
			FileService.SaveFile(FileName, boardService.GetBoardSaveState(), typeof(BoardSaveState));
		}

		public BoardSaveState LoadGame()
		{
			BoardSaveState boardSave = FileService.LoadFile(FileName, typeof(BoardSaveState)) as BoardSaveState;
			return boardSave;
		}

		public Boolean IsSaveAvailable()
		{
			return FileService.IsFileAvaible(FileName);
		}

		public void ClearSaveData()
		{
			FileService.ClearFile(FileName);
		}
	}
}
